package org.ddd.orderdemo.application.event.publish;

import com.google.common.eventbus.EventBus;
import org.ddd.orderdemo.application.event.Event;
import org.ddd.orderdemo.application.event.subscribe.Subscriber;

public class DefaultPublisher implements EventPublisher {


    private EventBus eventBus;

    public DefaultPublisher(EventBus eventBus) {
        this.eventBus = eventBus;
    }


    @Override
    public void init(Class<? extends Event> type, int bufferSize) {

    }

    @Override
    public void addSubscriber(Subscriber subscriber) {
        eventBus.register(subscriber);

    }

    @Override
    public void removeSubscriber(Subscriber subscriber) {
        eventBus.unregister(subscriber);
    }


    public boolean publish(Event event) {

        eventBus.post(event);

        return true;
    }

}
